<html>
	<head>
		<meta charset="UTF-8">
		<title>电厂数据监控</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">
				
				<!--标题栏-->
				<p class="content_title">数据监控 &nbsp;&nbsp;>&nbsp;&nbsp;电厂数据监控</p>
				<!--标题栏-->
				
				<!--tab-->
				<div class="layui-tab layui-tab-brief" lay-filter="tabFilter">
					<ul class="layui-tab-title">
						<li class="layui-this" lay-id="1">日</li>
						<li lay-id="2">周</li>
						<li lay-id="3">月</li>
						<li lay-id="4">年</li>
					</ul>
					<div class="layui-tab-content"></div>
				</div>  
				<!--tab-->
				
				<!--条件查询-->
				<div class="content_seach">
					<div class="layui-form">
						<div class="layui-form-item">
							<div class="layui-inline">
								<label class="layui-form-label">日期</label>
								<div class="layui-input-inline ml10 start">
									<input type="text" name="" id="dateStartDay"  placeholder="请选择时间" autocomplete="off" class="layui-input">
									<input type="hidden" name="" id="dateStartMonth"  placeholder="请选择时间" autocomplete="off" class="layui-input">
									<input type="hidden" name="" id="dateStartYear"  placeholder="请选择时间" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid"></div>
								<div class="layui-input-inline ml10 end">
									<input type="text" name="" id="dateEndHours"  placeholder="请选择时间" autocomplete="off" class="layui-input">
									<input type="hidden" name="" id="dateEndDay"  placeholder="请选择时间" autocomplete="off" class="layui-input">
									<input type="hidden" name="" id="dateEndMonth"  placeholder="请选择时间" autocomplete="off" class="layui-input">
									<input type="hidden" name="" id="dateEndYear" placeholder="请选择时间" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<div class="layui-input-inline"  style="width:300px;">
									<input type="radio" name="" value="0" title="标方">
									<input type="radio" name="" value="1" title="吉焦">
									<input type="radio" name="" value="1" title="吨">
								</div>
							</div>
							<button class="layui-btn layui-btn-warm search layui-btn-sm" id="search" lay-submit=""  lay-filter="search"><i class="layui-icon">&#xe615;</i>查询</button>
						</div>
					</div>
				</div>
				<!--条件查询-->
				
				<!--表格-->
				<div class="content_table">
					<script type="text/html" id="toolbarDemo">
						<div class="layui-btn-container">
							<a href="" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe669;</i> 刷新</a>
							<a class="layui-btn layui-btn-sm"id="configure"><i class="layui-icon">&#xe620;</i> 配置</a>
							<a class="layui-btn layui-btn-sm" id="tijiao"><i class="layui-icon">&#xe608;</i> 提交确认</a>
							<a class="layui-btn layui-btn-sm" id="approval"><i class="layui-icon">&#x1005;</i> 批准</a>
							<a class="layui-btn layui-btn-sm" id="cancelApproval"><i class="layui-icon">&#x1006;</i> 取消审批</a>
							<a class="layui-btn layui-btn-sm" id="contrastRange"><i class="layui-icon">&#xe663;</i> 设置对比范围</a>
						</div>
					</script>
					<div class="tabTable">
						<table id="table" lay-filter="tableFilter"></table>
						<div class="layui-table-page fr">
							<div id="layui-table-page1"></div>
						</div>
					</div>
				</div>
				<!--表格-->
			</div>
			
		</div>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script type="text/html" id="inputStandardConditionSumColor">
		  	{{#  if(d.inputStandardConditionSum != null){ }}
		  		{{#  if(d.dataStatus == 0){ }}<!--未提交黄色-->
		  			<span style="color: orange;">{{ d.inputStandardConditionSum }}</span>
		  		{{#  } else if(d.dataStatus == 1){ }}<!--未确认绿色-->
		  			<span style="color: #009688;">{{ d.inputStandardConditionSum }}</span>
		  		{{#   } }}
		  	{{#   } }}
		</script>
		<script>
			layui.use(['table', 'laydate', 'form','element'], function(){
				var table = layui.table,form = layui.form,laydate = layui.laydate,element = layui.element; 
				var upcomfig = []; // 存放监控里面没有提交的站点名称
				$(function() {// 初始化内容
					initList(1);
                });
                
                
                function initList(groupType){
					console.log(groupType);
					$.ajax({
						url: baseUrl + 'monitordata/getSiteConfigList',
						type: 'GET',
						dataType: 'json',
						async:false,
						data:{
							reportIndex:4,
							pageNo:1,
							siteType: 3,//电厂数据监控
							groupType: groupType   //1-按天 2-按周 3-按月 4-按年
						},
						traditional: true,
						timeout: 30000,
						success: function(res){
							console.log(res);
							var dataCols = [{
								field: 'date',
								title: '时间',
								align: 'center'
							}];
							var siteNames = '';
							$.each(res, function(i, item) {
								dataCols.push({
									field: 'list',
									title: item.siteName,
									align: 'center',
									templet: function(d) {
										console.log(i);
										if(d.list.length != 0){
											if(d.list[i].dataStatus == 0 || d.list[i].dataStatus == null || d.list[i].dataStatus == undefined){
												upcomfig.push({siteName: d.list[i].siteName,status: 0,isReport:1});
												return '<div style="color: orange;">'+d.list[i].inputStandardConditionSum+'</div>';
											}else if(d.list[i].dataStatus == 1){
												upcomfig.push({siteName: d.list[i].siteName,status: 1,isReport:1});
												return '<div style="color: #009688;">'+d.list[i].inputStandardConditionSum+'</div>';
											}else{
												console.log(d)
												return '<div>'+d.list[i].inputStandardConditionSum+'</div>';
											}
											
										}else{
											return '<div>0</div>';
										}
									}
								});
								//									拼接下面传递的参数;
								if(i == res.length - 1) {
									console.log(11)
									siteNames += item.siteName
								} else {
									siteNames += item.siteName + ',';
								}
//								siteNames += '&siteNames[]='+item.siteName;
							});
							var startTimes = crtTimeFtt();
							ajaxTable({
								idNode: '#table',
								page: true,
								url: 'monitordata/getListAll',
//								url:'monitordata/getTest',
								urlParme: '&siteType=3&groupType=' + groupType + '&siteNames=' + siteNames + '&startTime=' + startTimes + '+00:00&endTime=' + startTimes + '+23:59',
								dataCols:dataCols,
								successFull: function (res, curr, count){
									// console.log(res)
								}
							})
						}
					})
				}
				
				
				//条件查询
				form.on('submit(search)', function(data){
					var startData = $(".start [type = text]").val();
					var endData = $(".end [type = text]").val()
					console.log(startData);
					console.log(endData);
					//时间查询条件格式处理
					var startTime="";
					var endTime="";
					var urlParme="&siteType=3&groupType="+groupType;
					if(startData!="" && endData!="" && startData!=undefined && endData!=undefined && groupType==1){
						var houers= endData.split("-");
						console.log(houers);
						startTime=startData+"+"+$.trim(houers[0]);
						endTime=startData+"+"+$.trim(houers[1]);
						urlParme+="&startTime="+startTime+"&endTime="+endTime;
					}else if(startData!="" && endData!="" && startData!=undefined && endData!=undefined && groupType==2){
						startTime=startData+"+00:00";
						endTime=endData+"+23:59";
						urlParme+="&startTime="+startTime+"&endTime="+endTime;
					}else if(startData!="" && endData!="" && startData!=undefined && endData!=undefined && groupType==3){
						startTime=startData+"-01+00:00";
						endTime=endData+"-31+23:59";
						urlParme+="&startTime="+startTime+"&endTime="+endTime;
					}else if(startData!="" && endData!="" && startData!=undefined && endData!=undefined && groupType==4){
						startTime=startData+"-01-01+00:00";
						endTime=endData+"-12-31+23:59";
						urlParme+="&startTime="+startTime+"&endTime="+endTime;
					}
					
					console.log(startTime);
					console.log(endTime);
					
					$.ajax({
						url: baseUrl + 'monitordata/getSiteConfigList',
						type: 'GET',
						dataType: 'json',
						async:false,
						data:{
							reportIndex:4,
							pageNo:1,
							siteType: 3,//电厂数据监控
							groupType: groupType //1-按天 2-按周 3-按月 4-按年
						},
						traditional: true,
						timeout: 30000,
						success: function(res){
							console.log(res);
							var dataCols = [{
								field: 'date',
								title: '时间',
								align: 'center'
							}];
							var siteNames = '';
							$.each(res, function(i, item) {
								dataCols.push({
									field: 'list',
									title: item.siteName,
									align: 'center',
									templet: function(d) {
										console.log(i);
										if(d.list.length != 0){
											if(d.list[i].dataStatus == 0  || d.list[i].dataStatus == null || d.list[i].dataStatus == undefined){
												upcomfig.push({siteName: d.list[i].siteName,status: 0,isReport:1});
												return '<div style="color: orange;">'+d.list[i].inputStandardConditionSum+'</div>';
											}else if(d.list[i].dataStatus == 1){
												upcomfig.push({siteName: d.list[i].siteName,status: 1,isReport:1});
												return '<div style="color: #009688;">'+d.list[i].inputStandardConditionSum+'</div>';
											}else{
												console.log(d)
												return '<div>'+d.list[i].inputStandardConditionSum+'</div>';
											}
											
										}else{
											return '<div>0</div>';
										}
									}
								});
								//									拼接下面传递的参数;
								if(i == res.length - 1) {
									console.log(11)
									siteNames += item.siteName
								} else {
									siteNames += item.siteName + ',';
								}
//								siteNames += '&siteNames[]='+item.siteName;
							});
							urlParme='&siteType=3&groupType='+groupType+'&siteNames='+siteNames+'&startTime='+startTime+'&endTime='+endTime;
							ajaxTable({
								idNode: '#table',
								page:true,
								url: 'monitordata/getListAll',
//								url:'monitordata/getTest',
								urlParme:urlParme,
								dataCols:dataCols,
								successFull: function (res, curr, count){
									// console.log(res)
								}
							})
						}
					});
				});
				
				laydate.render({elem: '#dateStartDay',type: 'date'});
				laydate.render({elem: '#dateStartMonth',type: 'month'});
				laydate.render({elem: '#dateStartYear',type: 'year'});
				laydate.render({elem: '#dateEndHours',type: 'time',range: true});
				laydate.render({elem: '#dateEndDay',type: 'date'});
				laydate.render({elem: '#dateEndMonth',type: 'month'});
				laydate.render({elem: '#dateEndYear',type: 'year'});
				
				//监听Tab切换，以改变地址hash值
				var groupType = 1;
				element.on('tab(tabFilter)', function(){
					groupType=this.getAttribute('lay-id');
					if(groupType == 1){//日
						$("#dateStartDay").attr("type","text");
						$("#dateStartMonth").attr("type","hidden");
						$("#dateStartYear").attr("type","hidden");
						$("#dateEndHours").attr("type","text");
						$("#dateEndDay").attr("type","hidden");
						$("#dateEndMonth").attr("type","hidden");
						$("#dateEndYear").attr("type","hidden");
					}else if(groupType == 2){//周
						$("#dateStartDay").attr("type","text");
						$("#dateStartMonth").attr("type","hidden");
						$("#dateStartYear").attr("type","hidden");
						$("#dateEndHours").attr("type","hidden");
						$("#dateEndDay").attr("type","text");
						$("#dateEndMonth").attr("type","hidden");
						$("#dateEndYear").attr("type","hidden");
					}else if(groupType == 3){//月
						$("#dateStartDay").attr("type","hidden");
						$("#dateStartMonth").attr("type","text");
						$("#dateStartYear").attr("type","hidden");
						$("#dateEndHours").attr("type","hidden");
						$("#dateEndDay").attr("type","hidden");
						$("#dateEndMonth").attr("type","text");
						$("#dateEndYear").attr("type","hidden");
					}else if(groupType == 4){//年
						$("#dateStartDay").attr("type","hidden");
						$("#dateStartMonth").attr("type","hidden");
						$("#dateStartYear").attr("type","text");
						$("#dateEndHours").attr("type","hidden");
						$("#dateEndDay").attr("type","hidden");
						$("#dateEndMonth").attr("type","hidden");
						$("#dateEndYear").attr("type","text");
					}
					initList(groupType);
				});
				
				
				//监听工具条
				table.on('tool(tableFilter)', function(obj){
					var data = obj.data;
					if(obj.event === 'detail'){
						layer.msg('ID：'+ data.id + ' 的查看操作');
					} else if(obj.event === 'del'){
						layer.confirm('确定删除吗？', function(index){
							console.log(data);
							$.ajax({
								url: baseUrl+"/user/del",
								type: "POST",
								data:{"id":data.id},
								dataType: "json",
								success: function(data){
									if(data.code==200){
										obj.del();
										layer.close(index);
										layer.msg("删除成功", {icon: 6});
									}else{
										layer.msg("删除失败", {icon: 5});
									}
								}
							});
						});
					} else if(obj.event === 'edit'){
						layer.confirm('确定修改吗？', function(index){
							location.href="./adminEdit.html?pos=3&childPos=0&id="+data.id;
						});
					}
				});
				
				
				//刷新
				$('a[btn-renovate]').on('click',function(){
					window.location.reload();
				});

				
				/* 弹出提交确认 */
				$("#tijiao").click(function () {
					console.log(upcomfig);
					var upcomfig2 = []; // 状态为0  未提交
					var upcomfig3 = []; // 状态为1  已提交
					var upcomfig4 = []; // 状态为0  未提交——————去重
					var upcomfig5 = []; // 状态为1  已提交——————去重
////					循环数组
					$.each(upcomfig,function(i,item){
						if(item.status == 0){
							upcomfig2.push(item)
						}else{
							upcomfig3.push(item)
						}
					});
					upcomfig = [];
				
					$.each(upcomfig2,function(i,item){
//						upcomfig4
						if(upcomfig4.indexOf(item.siteName) == -1){
							upcomfig4.push(item.siteName);
							upcomfig.push({siteName: item.siteName,status: 0,isReport:1})
						};
					});
					$.each(upcomfig3,function(i,item){
//						upcomfig5
						if(upcomfig5.indexOf(item.siteName) == -1){
							upcomfig5.push(item.siteName);
						}
					});
					if(upcomfig5.length != 0){
						$.each(upcomfig5, function(i,item) {
							if(upcomfig4.indexOf(item) == -1){
								upcomfig.push({siteName: item,status: 1,isReport:1})
							}
						});
					};
					console.log(upcomfig4);
					console.log(upcomfig5);
					console.log(upcomfig);
//					设置缓存
					window.sessionStorage.setItem('plantComfig',JSON.stringify(upcomfig));
					/* 再弹出添加界面 */
					layer.open({
						type:2,
						title:"发布",
						skin:"myclass",
						area:["40%",'60%'],
						content:'submission.html?sitetype=3&operationType=1',//operationType=1提交确认
						end:function(){
							location.reload();
						}
					});
					return false;
				});
				
				/* 弹出批准 */
				$("#approval").click(function () {
					console.log(upcomfig);
					var upcomfig2 = []; // 状态为0  未提交
					var upcomfig3 = []; // 状态为1  已提交
					var upcomfig4 = []; // 状态为0  未提交——————去重
					var upcomfig5 = []; // 状态为1  已提交——————去重
////					循环数组
					$.each(upcomfig,function(i,item){
						if(item.status == 0){
							upcomfig2.push(item)
						}else{
							upcomfig3.push(item)
						}
					});
					upcomfig = [];
				
					$.each(upcomfig2,function(i,item){
//						upcomfig4
						if(upcomfig4.indexOf(item.siteName) == -1){
							upcomfig4.push(item.siteName);
							upcomfig.push({siteName: item.siteName,status: 0,isReport:1})
						};
					});
					$.each(upcomfig3,function(i,item){
//						upcomfig5
						if(upcomfig5.indexOf(item.siteName) == -1){
							upcomfig5.push(item.siteName);
						}
					});
					if(upcomfig5.length != 0){
						$.each(upcomfig5, function(i,item) {
							if(upcomfig4.indexOf(item) == -1){
								upcomfig.push({siteName: item,status: 1,isReport:1})
							}
						});
					};
					console.log(upcomfig4);
					console.log(upcomfig5);
					console.log(upcomfig);
//					设置缓存
					window.sessionStorage.setItem('plantComfig',JSON.stringify(upcomfig));
					/* 再弹出添加界面 */
					layer.open({
						type:2,
						title:"批准",
						skin:"myclass",
						area:["40%",'60%'],
						content:'submission.html?sitetype=3&operationType=2',//operationType=2批准
						end:function(){
							location.reload();
						}
					});
					return false;
				});
				
				/* 弹出取消批准 */
				$("#cancelApproval").click(function () {
					console.log(upcomfig);
					var upcomfig2 = []; // 状态为0  未提交
					var upcomfig3 = []; // 状态为1  已提交
					var upcomfig4 = []; // 状态为0  未提交——————去重
					var upcomfig5 = []; // 状态为1  已提交——————去重
////					循环数组
					$.each(upcomfig,function(i,item){
						if(item.status == 0){
							upcomfig2.push(item)
						}else{
							upcomfig3.push(item)
						}
					});
					upcomfig = [];
				
					$.each(upcomfig2,function(i,item){
//						upcomfig4
						if(upcomfig4.indexOf(item.siteName) == -1){
							upcomfig4.push(item.siteName);
							upcomfig.push({siteName: item.siteName,status: 0,isReport:1})
						};
					});
					$.each(upcomfig3,function(i,item){
//						upcomfig5
						if(upcomfig5.indexOf(item.siteName) == -1){
							upcomfig5.push(item.siteName);
						}
					});
					if(upcomfig5.length != 0){
						$.each(upcomfig5, function(i,item) {
							if(upcomfig4.indexOf(item) == -1){
								upcomfig.push({siteName: item,status: 1,isReport:1})
							}
						});
					};
					console.log(upcomfig4);
					console.log(upcomfig5);
					console.log(upcomfig);
//					设置缓存
					window.sessionStorage.setItem('plantComfig',JSON.stringify(upcomfig));
					/* 再弹出添加界面 */
					layer.open({
						type:2,
						title:"取消批准",
						skin:"myclass",
						area:["40%",'60%'],
						content:'submission.html?sitetype=3&operationType=3',//operationType=3取消批准
						end:function(){
							location.reload();
						}
					});
					return false;
				});
				
				/* 弹出对比范围 */
				$("#contrastRange").click(function () {
					/* 再弹出添加界面 */
					layer.open({
						type:2,
						title:"与昨天的对比范围",
						skin:"myclass",
						area:["40%",'60%'],
						content:'contrastRange.html',
						end:function(){
							location.reload();
						}
					});
					return false;
				});
				
				/* 配置 */
				$("#configure").click(function () {
					/* 再弹出添加界面 */
					layer.open({
						type:2,
						title:"配置",
						skin:"myclass",
						area:["720",'470'],
						content:'configure.html?reportIndex=4',
						end:function(){
							location.reload();
						}
					});
					return false;
				});
				


				
			});
		</script>
	</body>
</html>